package com.djf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.djf.entity.ProcessInstance;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 流程实例Mapper接口
 * 
 * @author djf
 * @since 2024-01-01
 */

public interface ProcessInstanceMapper extends BaseMapper<ProcessInstance> {

    /**
     * 根据流程实例ID查询
     */
    @Select("SELECT * FROM process_instance WHERE process_instance_id = #{processInstanceId} AND deleted = 0")
    ProcessInstance selectByProcessInstanceId(@Param("processInstanceId") String processInstanceId);

    /**
     * 根据业务Key查询
     */
    @Select("SELECT * FROM process_instance WHERE business_key = #{businessKey} AND deleted = 0")
    List<ProcessInstance> selectByBusinessKey(@Param("businessKey") String businessKey);

    /**
     * 根据发起人查询
     */
    @Select("SELECT * FROM process_instance WHERE starter_user_id = #{starterUserId} AND deleted = 0 ORDER BY create_time DESC")
    List<ProcessInstance> selectByStarterUserId(@Param("starterUserId") String starterUserId);

    /**
     * 根据状态查询
     */
    @Select("SELECT * FROM process_instance WHERE status = #{status} AND deleted = 0 ORDER BY create_time DESC")
    List<ProcessInstance> selectByStatus(@Param("status") String status);
}